package com.qf.controller;

import com.qf.ResultVo;
import com.qf.User;
import com.qf.service.IUserService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("user")
@CrossOrigin
public class UserController {
    
    @Autowired
    private IUserService userService;
    
    @GetMapping("login")
    public ResultVo login(@Param("userAccount") String userAccount,
                          @Param("userPwd") String userPwd){
        User user = new User();
        user.setUserAccount(userAccount);
        user.setUserPwd(userPwd);
       
       
        ResultVo vo = userService.selectUser(user);
        return vo;
    }
    
    @PostMapping("register")
    public ResultVo register(User user){
        user.setUserName(user.getUserAccount());
        ResultVo vo = userService.insertUser(user);
        return vo;
    }
    
    @PostMapping("update")
    public ResultVo update(@RequestBody User user){
        ResultVo vo = userService.updateUser(user);
        return vo;
    }
    
    @GetMapping("searchId")
    public User searchUserId(String userAccount){
        User user = userService.selectUserByAccount(userAccount);
        return user;
    }
}
